import { MiddlewareConsumer, Module, NestModule } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { EnvModule } from "./modules/common/env";
import { TypeormModule } from "./modules/common/typeorm";
import { LoginModule } from "./modules/login";
import { UserModule } from "./modules/user";
import { RoleModule } from "./modules/role";
import { UserRoleModule } from "./modules/user-role";
import { RsaModule } from "./modules/rsa";
import { RedisModule } from "./modules/common/redis";
import { MenuModule } from "./modules/menu";
import { DecryptKeyMiddleware } from "./modules/common/encrypt";
import { ReqDataDecryptMiddleware } from "./modules/common/encrypt";
import { ResDataEncryptMiddleware } from "./modules/common/encrypt";
import { ReqResJsonHandleMiddleware } from "./modules/common/json";
import { DictModule } from './modules/dict/dict.module';

@Module({
  imports: [EnvModule, TypeormModule, LoginModule, UserModule, RoleModule, UserRoleModule, RsaModule, RedisModule, MenuModule, DictModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule{

  configure(consumer: MiddlewareConsumer): any {
    // 注册全局中间件
    consumer.apply(DecryptKeyMiddleware).forRoutes('*')
    consumer.apply(ReqDataDecryptMiddleware).forRoutes('*')
    consumer.apply(ResDataEncryptMiddleware).forRoutes('*')
    consumer.apply(ReqResJsonHandleMiddleware).forRoutes('*')
  }

}
